.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
.\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
.\"
.TH GETDATE 3C "Nov 1, 2003"
.SH NAME
getdate \- convert user format date and time
.SH SYNOPSIS
.LP
.nf
#include <time.h>

\fBstruct tm *\fR\fBgetdate\fR(\fBconst char *\fR\fIstring\fR);
extern int getdate_err;
.fi

.SH DESCRIPTION
.sp
.LP
The \fBgetdate()\fR function converts user-definable date and/or time
specifications pointed to by \fIstring\fR to a \fBtm\fR structure. The \fBtm\fR
structure is defined in the <\fBtime.h\fR> header.
.sp
.LP
User-supplied templates are used to parse and interpret the input string.  The
templates are  text files created by the user and identified via the
environment variable \fBDATEMSK\fR. Each line in the template represents an
acceptable date and/or time specification using  conversion specifications
similar to those used by \fBstrftime\fR(3C) and \fBstrptime\fR(3C). Dates
before 1902 and after 2037 are illegal. The first line in the template that
matches the input specification is used for interpretation and conversion into
the internal time format.
.SS "Conversion Specifications"
.sp
.LP
The following conversion specifications are supported:
.sp
.ne 2
.na
\fB\fB%%\fR\fR
.ad
.RS 6n
Same as \fB%\fR.
.RE

.sp
.ne 2
.na
\fB\fB%a\fR\fR
.ad
.RS 6n
Locale's abbreviated weekday name.
.RE

.sp
.ne 2
.na
\fB\fB%A\fR\fR
.ad
.RS 6n
Locale's full weekday name.
.RE

.sp
.ne 2
.na
\fB\fB%b\fR\fR
.ad
.RS 6n
Locale's abbreviated month name.
.RE

.sp
.ne 2
.na
\fB\fB%B\fR\fR
.ad
.RS 6n
Locale's full month name.
.RE

.sp
.ne 2
.na
\fB\fB%c\fR\fR
.ad
.RS 6n
Locale's appropriate date and time representation.
.RE

.sp
.ne 2
.na
\fB\fB%C\fR\fR
.ad
.RS 6n
Century number (the year divided by 100 and truncated to an integer as a
decimal number [1,99]); single digits are preceded by 0; see
\fBstandards\fR(7). If used without the \fB%y\fR specifier, this format
specifier will assume the current year offset in whichever century is
specified. The only valid years are between 1902-2037.
.RE

.sp
.ne 2
.na
\fB\fB%d\fR\fR
.ad
.RS 6n
day of month [01,31]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%D\fR\fR
.ad
.RS 6n
Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
.RE

.sp
.ne 2
.na
\fB\fB%e\fR\fR
.ad
.RS 6n
Same as \fB%d\fR.
.RE

.sp
.ne 2
.na
\fB\fB%h\fR\fR
.ad
.RS 6n
Locale's abbreviated month name.
.RE

.sp
.ne 2
.na
\fB\fB%H\fR\fR
.ad
.RS 6n
Hour (24-hour clock) [0,23]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%I\fR\fR
.ad
.RS 6n
Hour (12-hour clock) [1,12]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%j\fR\fR
.ad
.RS 6n
Day number of the year [1,366]; leading zeros are permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%m\fR\fR
.ad
.RS 6n
Month number [1,12]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%M\fR\fR
.ad
.RS 6n
Minute [0,59]; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%n\fR\fR
.ad
.RS 6n
Any white space.
.RE

.sp
.ne 2
.na
\fB\fB%p\fR\fR
.ad
.RS 6n
Locale's equivalent of either a.m. or p.m.
.RE

.sp
.ne 2
.na
\fB\fB%r\fR\fR
.ad
.RS 6n
Appropriate time representation in the 12-hour clock format with \fB%p\fR.
.RE

.sp
.ne 2
.na
\fB\fB%R\fR\fR
.ad
.RS 6n
Time as \fB%H\fR:\fB%M\fR.
.RE

.SS "SUSv3"
.sp
.ne 2
.na
\fB\fB%S\fR\fR
.ad
.RS 6n
Seconds [0,60]; leading zero is permitted but not required. The range of values
is [00,60] rather than [00,59] to allow for the occasional leap second.
.RE

.SS "Default and other standards"
.sp
.ne 2
.na
\fB\fB%S\fR\fR
.ad
.RS 6n
Seconds [0,61]; leading zero is permitted but not required. The range of values
is [00,61] rather than [00,59] to allow for the occasional leap second and even
more occasional double leap second.
.RE

.sp
.ne 2
.na
\fB\fB%t\fR\fR
.ad
.RS 6n
Any white space.
.RE

.sp
.ne 2
.na
\fB\fB%T\fR\fR
.ad
.RS 6n
Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
.RE

.sp
.ne 2
.na
\fB\fB%U\fR\fR
.ad
.RS 6n
Week number of the year as a decimal number [0,53], with Sunday as the first
day of the week; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%w\fR\fR
.ad
.RS 6n
Weekday as a decimal number [0,6], with 0 representing Sunday.
.RE

.sp
.ne 2
.na
\fB\fB%W\fR\fR
.ad
.RS 6n
Week number of the year as a decimal number [0,53], with Monday as the first
day of the week; leading zero is permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%x\fR\fR
.ad
.RS 6n
Locale's appropriate date representation.
.RE

.sp
.ne 2
.na
\fB\fB%X\fR\fR
.ad
.RS 6n
Locale's appropriate time representation.
.RE

.sp
.ne 2
.na
\fB\fB%y\fR\fR
.ad
.RS 6n
Year within century. When a century is not otherwise specified, values in the
range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive);
values in the range 00-68 refer to years in the twenty-first century (2000 to
2068 inclusive).
.RE

.sp
.ne 2
.na
\fB\fB%Y\fR\fR
.ad
.RS 6n
Year, including the century (for example, 1993).
.RE

.sp
.ne 2
.na
\fB\fB%Z\fR\fR
.ad
.RS 6n
Time zone name or no characters if no time zone exists.
.RE

.SS "Modified Conversion Specifications"
.sp
.LP
Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
modifier characters to indicate that an alternative format or specification
should be used rather than the one normally used by the unmodified
specification. If the alternative format or specification does not exist in the
current locale,  the behavior be as if the unmodified  conversion specification
were used.
.sp
.ne 2
.na
\fB\fB%Ec\fR\fR
.ad
.RS 7n
Locale's alternative appropriate date and time representation.
.RE

.sp
.ne 2
.na
\fB\fB%EC\fR\fR
.ad
.RS 7n
Name of the base year (period) in the locale's alternative representation.
.RE

.sp
.ne 2
.na
\fB\fB%Ex\fR\fR
.ad
.RS 7n
Locale's alternative date representation.
.RE

.sp
.ne 2
.na
\fB\fB%EX\fR\fR
.ad
.RS 7n
Locale's alternative time representation.
.RE

.sp
.ne 2
.na
\fB\fB%Ey\fR\fR
.ad
.RS 7n
Offset from \fB%EC\fR (year only) in the locale's alternative representation.
.RE

.sp
.ne 2
.na
\fB\fB%EY\fR\fR
.ad
.RS 7n
Full alternative year representation.
.RE

.sp
.ne 2
.na
\fB\fB%Od\fR\fR
.ad
.RS 7n
Day of the month using the locale's alternative  numeric symbols; leading zeros
are permitted but not required.
.RE

.sp
.ne 2
.na
\fB\fB%Oe\fR\fR
.ad
.RS 7n
Same as \fB%Od\fR.
.RE

.sp
.ne 2
.na
\fB\fB%OH\fR\fR
.ad
.RS 7n
Hour (24-hour clock) using the locale's alternative numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OI\fR\fR
.ad
.RS 7n
Hour (12-hour clock) using the locale's alternative numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%Om\fR\fR
.ad
.RS 7n
Month using the locale's alternative numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OM\fR\fR
.ad
.RS 7n
Minutes using the locale's alternative numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OS\fR\fR
.ad
.RS 7n
Seconds using the locale's alternative numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OU\fR\fR
.ad
.RS 7n
Week number of the year (Sunday as the first day of the week) using the
locale's alternative numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%Ow\fR\fR
.ad
.RS 7n
Number of the weekday (Sunday=0) using the  locale's alternative numeric
symbols.
.RE

.sp
.ne 2
.na
\fB\fB%OW\fR\fR
.ad
.RS 7n
Week number of the year (Monday as the first day of the week) using the
locale's alternative numeric symbols.
.RE

.sp
.ne 2
.na
\fB\fB%Oy\fR\fR
.ad
.RS 7n
Year (offset from \fB%C\fR) in the locale's alternative  representation and
using the locale's alternative numeric symbols.
.RE

.SS "Internal Format Conversion"
.sp
.LP
The following rules are applied for converting the input specification into the
internal format:
.RS +4
.TP
.ie t \(bu
.el o
If only the weekday is given, today is assumed if the given day is equal to the
current day and next week if it is less.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If only the month is given, the current month is assumed if the given month is
equal to the current month and next year if it is less and no year is given.
(The first day of month is assumed if no day is given.)
.RE
.RS +4
.TP
.ie t \(bu
.el o
If only the year is given, the values of the \fBtm_mon\fR, \fBtm_mday\fR,
\fBtm_yday\fR, \fBtm_wday\fR, and \fBtm_isds\fRt members of the returned
\fBtm\fR structure are not specified.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If the century is given, but the year within the century is not given, the
current year within the century is assumed.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If no hour, minute, and second are given, the current hour, minute, and second
are assumed.
.RE
.RS +4
.TP
.ie t \(bu
.el o
If no date is given, today is assumed if the given hour is greater than the
current hour and tomorrow is assumed if it is less.
.RE
.SS "General Specifications"
.sp
.LP
A conversion specification that is an ordinary character is executed by
scanning the next character from the buffer. If the character scanned from the
buffer differs from the one comprising the conversion specification, the
specification fails, and the differing and subsequent characters remain
unscanned.
.sp
.LP
A series of conversion specifications composed of \fB%n\fR, \fB%t\fR, white
space characters, or any combination is executed by scanning up to the first
character that is not white space (which remains unscanned), or until no more
characters can be scanned.
.sp
.LP
Any other conversion specification is executed by scanning characters until a
character matching the next conversion specification is scanned, or until no
more characters can be scanned.  These characters, except the one matching the
next conversion specification, are then compared to the locale values
associated with the conversion specifier.  If a match is found, values for the
appropriate \fItm\fR structure members are set to values corresponding to the
locale information. If no match is found, \fBgetdate()\fR fails and no more
characters are scanned.
.sp
.LP
The month names, weekday names, era names, and alternative numeric symbols can
consist of any combination of upper and lower case letters.  The user can
request that the input date or time specification be in a specific language by
setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C).
.SH RETURN VALUES
.sp
.LP
If successful, \fBgetdate()\fR returns a pointer to a \fBtm\fR structure;
otherwise, it returns \fINULL\fR and sets the global variable \fBgetdate_err\fR
to indicate the error. Subsequent calls to \fBgetdate()\fR alter the contents
of \fBgetdate_err\fR.
.sp
.LP
The following is a complete list of the  \fBgetdate_err\fR settings and their
meanings:
.sp
.ne 2
.na
\fB\fB1\fR\fR
.ad
.RS 5n
The \fBDATEMSK\fR environment variable is null or undefined.
.RE

.sp
.ne 2
.na
\fB\fB2\fR\fR
.ad
.RS 5n
The template file cannot be opened for reading.
.RE

.sp
.ne 2
.na
\fB\fB3\fR\fR
.ad
.RS 5n
Failed to get file status information.
.RE

.sp
.ne 2
.na
\fB\fB4\fR\fR
.ad
.RS 5n
The template file is not a regular file.
.RE

.sp
.ne 2
.na
\fB\fB5\fR\fR
.ad
.RS 5n
An error is encountered while reading the template file.
.RE

.sp
.ne 2
.na
\fB\fB6\fR\fR
.ad
.RS 5n
The \fBmalloc()\fR function failed (not enough memory is available).
.RE

.sp
.ne 2
.na
\fB\fB7\fR\fR
.ad
.RS 5n
There is no line in the template that matches the input.
.RE

.sp
.ne 2
.na
\fB\fB8\fR\fR
.ad
.RS 5n
The input specification is invalid (for example, \fBFebruary 31\fR).
.RE

.SH USAGE
.sp
.LP
The \fBgetdate()\fR function makes explicit use of macros described on the
\fBctype\fR(3C) manual page.
.SH EXAMPLES
.LP
\fBExample 1 \fRExamples of the \fBgetdate()\fR function.
.sp
.LP
The following example shows the possible contents of a template:

.sp
.in +2
.nf
%m
%A %B %d %Y, %H:%M:%S
%A
%B
%m/%d/%y %I %p
%d,%m,%Y %H:%M
at %A the %dst of %B in %Y
run job at %I %p,%B %dnd
%A den %d. %B %Y %H.%M Uhr
.fi
.in -2

.sp
.LP
The following are examples of valid input specifications for the above
template:

.sp
.in +2
.nf
getdate("10/1/87 4 PM")
getdate("Friday")
getdate("Friday September 19 1987, 10:30:30")
getdate("24,9,1986 10:30")
getdate("at monday the 1st of december in 1986")
getdate("run job at 3 PM, december 2nd")
.fi
.in -2

.sp
.LP
If the \fBLANG\fR environment variable is set to  \fBde\fR (German), the
following is valid:

.sp
.in +2
.nf
getdate("freitag den 10. oktober 1986 10.30 Uhr")
.fi
.in -2

.sp
.LP
Local time and date specification are also supported. The following examples
show how local date and time specification can be defined in the template.

.sp

.sp
.TS
box;
l | l
l | l .
Invocation	Line in Template
_
getdate("11/27/86")	%m/%d/%y
getdate("27.11.86")	%d.%m.%y
getdate("86-11-27")	%y-%m-%d
getdate("Friday 12:00:00")	%A %H:%M:%S
.TE

.sp
.LP
The following examples illustrate the Internal Format Conversion rules. Assume
that the current date is Mon Sep 22 12:19:47 EDT 1986 and the \fBLANG\fR
environment variable is not set.

.sp

.sp
.TS
box;
l | l | l
l | l | l .
Input	Template Line 	Date
_
\fBMon\fR	\fB%a\fR	Mon Sep 22 12:19:48 EDT 1986
\fBSun\fR	\fB%a\fR	Sun Sep 28 12:19:49 EDT 1986
\fBFri\fR	\fB%a\fR	Fri Sep 26 12:19:49 EDT 1986
\fBSeptember\fR	\fB%B\fR	Mon Sep  1 12:19:49 EDT 1986
\fBJanuary\fR	\fB%B\fR	Thu Jan  1 12:19:49 EST 1987
\fBDecember\fR	\fB%B\fR	Mon Dec  1 12:19:49 EDT 1986
\fBSep Mon\fR	\fB%b %a\fR	Mon Sep  1 12:19:50 EDT 1986
\fBJan Fri\fR	\fB%b %a\fR	Fri Jan  2 12:19:50 EST 1987
\fBDec Mon\fR	\fB%b %a\fR	Mon Dec  1 12:19:50 EST 1986
\fBJan Wed 1989\fR	\fB%b\fR \fB%a\fR \fB%Y\fR	Wed Jan  4 12:19:51 EST 1989
\fBFri 9\fR	\fB%a %H\fR	Fri Sep 26 09:00:00 EDT 1986
\fBFeb 10:30\fR	\fB%b %H:%S\fR	Sun Feb  1 10:00:30 EST 1987
\fB10:30\fR	\fB%H:%M\fR	Tue Sep 23 10:30:00 EDT 1986
\fB13:30\fR	\fB%H:%M\fR	Mon Sep 22 13:30:00 EDT 1986
.TE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
l | l
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
CSI	Enabled
_
Interface Stability	Standard
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.sp
.LP
.BR ctype (3C),
.BR mktime (3C),
.BR setlocale (3C),
.BR strftime (3C),
.BR strptime (3C),
.BR attributes (7),
.BR environ (7),
.BR standards (7)
